<template>
<div  element-loading-background="rgba(0, 0, 0, 0.8)" v-loading="loading" style='width:100%;height:100%;' class='container'>
  <div class='flex align-end justify-between header-wrapper' >
    <div class='weather'>
      <span>天气</span>
      <span class='highlight' style='margin:0 10px'>{{weather}}</span>
      <span>{{date}}</span>
      <span>周{{weekMapping[week]}}</span>
      <span class='highlight'>{{time}}</span>
    </div>
    <div class='title'>菜东家可视化数据展示中心</div>
    <div class='info'>
      <span>平台安全运营</span>
      <span class='highlight'>{{days}}天</span>
      <span>状态</span>
      <span class='highlight'>安全</span>
    </div>
  </div>
  <div class="view-wrapper" >
    <template v-for="item in checkListMap">
      <div class="items" v-if="item.title" :key="item.id" :class="item.type === 'map' ? 'items-map' : ''">
        <div class="title-wrapper">
          <p>{{ item.title }}</p>
        </div>
        <div
          v-loading="item.loading"
          element-loading-background="rgba(0, 0, 0, 0.6)"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          v-if="item.type != 'number'"
          :id="'chart' + item.id"
          class="chart"
        ></div>
        <div
          v-else
          v-loading="item.loading"
          element-loading-background="rgba(0, 0, 0, 0.6)"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          class="transaction-wrapper"
        >
          <div class="total-wrapper">
            <div class="number">
              {{ item.dataOption.find((item) => item.name === "总计").value }}
            </div>
            <div class="text">总交易额</div>
          </div>
          <div class="sub-wrapper flex align-center justify-around">
            <div class="flex align-center">
              <img src="@/assets/images/rocket.png" />
              <div>
                <div class="flex">
                  <span class="text">今日配送金额</span>
                 
                </div>
                <div class="number">
                  {{
                    item.dataOption.find((item) => item.name === "今日").value
                  }}
                </div>
              </div>
            </div>
            <div class="flex align-center">
              <img src="@/assets/images/rocket.png" />
              <div>
                <div class="flex">
                  <span class="text">本月配送金额</span>
                 
                </div>
                <div class="number">
                  {{
                    item.dataOption.find((item) => item.name === "本月").value
                  }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </template>
  </div>
</div>

</template>

<script>
import axios from "axios";
import { generateChart } from "./modules/generateChart";
import formatData from './modules/formatData'
import apiMapping from './modules/apiMapping'
import moment from 'moment'

export default {
  data() {
    return {
      checkListMap: [],
      baseUrl:process.env.NODE_ENV === "development" ? "/temp/" : window.location.origin + '/I/',
      loading:false,
      date:moment().format('YYYY-MM-DD'),
      time:moment().format('HH:mm:ss'),
      week:moment().format('E'),
      weather:'加载中',
      weekMapping:{
        '1':'一',
        '2':'二',
        '3':'三',
        '4':'四',
        '5':'五',
        '6':'六',
        '7':'日'
      },
      days:'0'
    };
  },
  mixins: [generateChart],
  watch:{
    $route(){
      this.getData()
    }
  },
  created() {
    this.days = this.getDistanceSpecifiedTime()
    this.getData()
    setInterval(()=>{
      this.time = moment().format('HH:mm:ss')
    },1000)
    axios.get("https://devapi.qweather.com/v7/weather/now?key=8235a501c4eb4e7bbf82f69da07a183d&location=115.857972,28.682976").then(res=>{
      this.weather = res.data.now.text
    })

  },
  methods:{
    getDistanceSpecifiedTime() {
        var EndTime = new Date();
        var NowTime = new Date(1483200000000);
        var t = EndTime.getTime() - NowTime.getTime();
        var d = Math.floor(t / 1000 / 60 / 60 / 24);
        var h = Math.floor(t / 1000 / 60 / 60 % 24);
        var m = Math.floor(t / 1000 / 60 % 60);
        var s = Math.floor(t / 1000 % 60);
        return d
    },
    getData(){
      this.loading = true
      axios.get(this.baseUrl + this.$route.params.pathMatch,).then((res) => {
        if (res.data && res.data.data && res.data.data) {
          this.checkListMap = res.data.data.data;
          this.checkListMap.forEach((item) => {
            item.dataOption = item.dataType === 1 ? item.dynamicData : (item.isEdited ? item.staticData : (item.dynamicData ? item.dynamicData : item.staticData))
            if (item.dataType === 1) {
              item.loading = true;
              apiMapping[item.title]().then((res) => {
                formatData(item,res)
                item.loading = false;
              });
            }
            if (item.id) {
              this.$nextTick(() => {
                if (item.type != "number") {
                  this.generateChart(item);
                }
              });
            }
          });
        } else {
          this.$message.warning("链接已过期或不存在");
        }
      },fail=>{
        this.$message.warning("链接已过期或不存在");
      }).finally(()=>{
        this.loading = false
      });
    }
  }
};
</script>

<style lang='scss' scoped>
/deep/.el-loading-spinner{
    display: flex;
    align-items: center;
    justify-content: center;
    .el-icon-loading{
      color:#3fb1e3;
    }
    .el-loading-text{
      color:#fff;
      margin-left:5px;
    }
}
.flex {
  display: flex;
}
.align-center {
  align-items: center;
}

.align-end{
  align-items: flex-end;
}

.justify-between {
  justify-content: space-between;
}
.justify-around {
  justify-content: space-around;
}
.container{
      background: rgb(38, 53, 116);

  // background: rgb(14,19,63);
}
.header-wrapper{
  color:#fff;
  padding:0 20px;
  height:60px;
  .title{
    font-size: 26px;
    font-family: Adobe Heiti Std;
    font-weight: bold;
    align-self: center;
  }
  .weather{
    font-size:16px;
  }
  .highlight{
    color: #58D2CA;
  }
}

.view-wrapper {
  width: 100%;
  padding: 0 10px 10px 10px;
  height: calc(100% - 60px);
  display: grid;
  grid-template-columns:repeat(3,33.3%);
  grid-template-rows:repeat(3,33.3%);
  .transaction-wrapper {
    position: absolute;
    padding: 15px;
    height: calc(100% - 38px);
    width: 100%;
    overflow: hidden;
    .number {
      background: linear-gradient(0deg, #76c0ff 0%, #5dd7ff 100%);
      background-clip: text;
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      font-weight: 800;
    }
    .total-wrapper {
      border: 1px solid rgb(52, 108, 172);
      margin: 0px 30px;
      text-align: center;
      padding: 5%;
      .number {
        font-size: 2.3rem;
        margin-bottom: 10px;
      }
      .text {
        color: #fff;
        font-size: 22px;
        font-weight: 800;
      }
    }
    .sub-wrapper {
      margin-top: 5%;
      color: #fff;
      img {
        width: 26px;
        height: 30px;
        margin-right: 10px;
      }
      .number {
        font-size: 20px;
      }
      .text {
        font-size: 10px;
      }
    }
  }
  .items-map{
    grid-row: span 2;
    
  }
  .items {
    display: inline-block;
    border: 1px solid rgb(52, 108, 172);
    margin: 10px;
    position: relative;
    // background: rgb(13,21,54);
    //   background: rgb(38, 53, 116);

    .chart {
      width: 100%;
      height: calc(100% - 38px);
    }
    .title-wrapper {
      padding: 10px;
      background: rgb(42, 64, 132);
      p {
        background: linear-gradient(
          0deg,
          #8be3f2 0%,
          #90cae7 37.109375%,
          #e0f0f8 100%
        );
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        font-weight: 500;
      }
    }
  }
}

</style>